package com.clw.template.admin.controller;


import com.clw.template.dto.UpdateRolePermission;
import com.clw.template.service.ISysRolePermissionRelationService;
import com.clw.template.util.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 后台用户角色和权限关系表 前端控制器
 * </p>
 *
 * @author clw
 * @since 2019-11-01
 */
@Api(tags = "SysRolePermissionRelationController",description = "后台用户角色和权限关系表")
@RestController
@RequestMapping("/admin/rolePermissionRelation")
public class SysRolePermissionRelationController {

    @Autowired
    private ISysRolePermissionRelationService sysRolePermissionRelationService;

    @PreAuthorize("hasAuthority('sys:rolePermissionRelation:getByRole')")
    @ApiOperation("根据角色id查询权限id列表")
    @GetMapping("getByRole/{id}")
    public CommonResult<List<Long>> getByRole(@PathVariable Long id){

        return CommonResult.success(sysRolePermissionRelationService.getByRole(id));
    }

    @PreAuthorize("hasAuthority('sys:rolePermissionRelation:updateByRole')")
    @ApiOperation("根据角色id修改角色权限")
    @PutMapping("updateByRole")
    public CommonResult updateByRole(@RequestBody UpdateRolePermission updateRolePermission){
        sysRolePermissionRelationService.updateByRole(updateRolePermission);
        return CommonResult.success();
    }

}
